package com.ymatou.iapi.godmch.testcase;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.godmch.parameter.applySupplierBean;
import com.ymatou.iapi.godmch.parameter.createIndepMchBean;
import com.ymatou.iapi.godmch.parameter.createSupplierCodeBean;
import com.ymatou.iapi.godmch.service.createIndepMchCall;
import com.ymatou.iapi.godmch.service.createSupplierCodeCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.shenqi.GodmchManageCallService;
import com.ymttest.database.model.invite_code;
import com.ymttest.database.sqlwapper.godmch.invite_codeWapper;
/**
*创建供货商邀请码
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_createSupplierCode{
	private static createSupplierCodeBean bean;
	private static createSupplierCodeCall call;
	private invite_codeWapper inviteCodeWapper=new invite_codeWapper();
	
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("创建供货商邀请码");
	}

	@Before
	public void caseUp() {
		bean=new createSupplierCodeBean();
		call=new createSupplierCodeCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(call.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_createSupplierCode_001() {
		Logger.start(true,"创建供货商邀请码-验证商户是独立商户");
		try {

			createIndepMchBean createIndepMchBean=GodmchManageCallService.InitCreateIndepMchBean();
            createIndepMchCall createIndepMchCall=GodmchManageCallService.CreateIndepMchCall(createIndepMchBean);
            
            bean.setMchId(createIndepMchCall.getmchId());
			call.setData(bean);
			call.callService();			
			//验证点
			invite_code model=inviteCodeWapper.selectByCode(call.getCode());
	        Logger.verifyEquals("200", call.getStatusCode1(), "验证返回成功status值");
	        Logger.verifyEquals("请求成功", call.getMessage(), "验证返回成功Message值");
	        Logger.verifyEquals(model.getInviteCode(), call.getCode(), "验证数据库invite_code中的inviteCode与返回code一致");
	        Logger.verifyEquals(3, model.getCodeRole(), "验证数据库invite_code中的CodeRole与返回CodeRole一致");
	        Logger.verifyEquals(0, model.getRoleType(), "验证数据库invite_code中的RoleType与返回RoleType一致");
	        Logger.verifyEquals(null, model.getExpireTime(), "验证数据库invite_code中的ExpireTime=null表示是永久邀请码");	
			
	        
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_createSupplierCode_003() {
		Logger.start(true,"创建供货商邀请码-验证商户是平台渠道");
		try {
			
			Integer mchId=GodmchManageCallService.CreateSellerMch();
            
            bean.setMchId(mchId);
			call.setData(bean);
			call.callService();			
			//验证点
	        Logger.verifyEquals("5000", call.getStatusCode1(), "验证返回成功status值");
	        Logger.verifyEquals("非独立云主商户禁止创建供货商邀请码", call.getMessage(), "验证返回成功Message值");
	        
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_createSupplierCode_004() {
		Logger.start(true,"创建供货商邀请码-验证商户Id不存在");
		try {
            bean.setMchId(999999);
			call.setData(bean);
			call.callService();			
			
	        Logger.verifyEquals("5000", call.getStatusCode1(), "验证返回成功status值");
	        Logger.verifyEquals("商户不存在", call.getMessage(), "验证返回成功Message值");
	        
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_createSupplierCode_005() {
		Logger.start(true,"创建供货商邀请码-验证商户Id为空");
		try {
			
           // bean.setMchId(999999);
			call.setData(bean);
			call.callService();			
			
	        Logger.verifyEquals("4001", call.getStatusCode1(), "验证返回成功status值");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}